# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/7/14 14:50
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : open_order.py
# @Software: PyCharm
# @Version: 2.7.5
from . import Session
from db.models import TOpenOrderKernel, TOpenInsureinfoKernel


def save_open_order_kernel(*args):
	session = Session()
	try:
		result = session.execute(
			TOpenOrderKernel.__table__.insert().prefix_with('IGNORE'),
			{'biPremium': args[0],
			 'ciPremium': args[1],
			 'carshipTax': args[2],
			 'totalCost': args[3],
			 'orderTime': args[4],
			 'biProposalNo': args[5],
			 'ciProposalNo': args[6],
			 'serviceNo': args[7],
			 'status': args[8],
			 'payState': args[9],
			 'appId': args[10],
			 'payAmount': args[11],
			 'rebates': args[12],
			 'msg': args[13],
			 'commission_status': args[14],
			 }
		)
		session.commit()
		return result.lastrowid
	except Exception as e:
		session.rollback()
		raise e


def save_open_insurance_kernel(*args):
	session = Session()
	try:
		result = session.execute(
			TOpenInsureinfoKernel.__table__.insert(),
			{'ciStartDate': args[0],
			 'biStartDate': args[1],
			 'biPolicyNo': args[2],
			 'ciPolicyNo': args[3],
			 'insureCode': args[4],
			 'insureCity': args[5],
			 'ownerName': args[6],
			 'ownerId': args[7],
			 'ownerMobile': args[8],
			 'vinNo': args[9],
			 'engineNo': args[10],
			 'model': args[11],
			 'licenseNo': args[12],
			 'registerDate': args[13],
			 'isTrans': args[14],
			 'transDate': args[15],
			 'content': args[16],
			 'insuredInfo': args[17],
			 'policyholder': args[18],
			 'addresseeName': args[19],
			 'addresseeMobile': args[20],
			 'addresseeProvince': args[21],
			 'addresseeCity': args[22],
			 'addresseeCounty': args[23],
			 'addresseeDetails': args[24],
			 't_open_order_id': args[25],
			 }
		)
		session.commit()
		return result.lastrowid
	except Exception as e:
		session.rollback()
		raise e

